export class InterAd {
    constructor(id) {
        this.adId = id
        this.ad = null
        this.timer = null
        this.createAd()
    }
    createAd() {
        if (qq.createInterstitialAd) {
            this.ad = qq.createInterstitialAd({
                adUnitId: this.adId
            });
            this.ad.load().catch((err) => {
                console.error('load', err)
            })
            this.ad.onLoad(() => {
                console.log('onLoad event emit')
            })
            this.ad.onClose(() => {
                console.log('close event emit')
            })
            this.ad.onError((e) => {
                console.log('error', e)
            })
        }
    }

    showAd() {
        if (this.ad) {
            this.ad.show().catch((err) => {
                
                this.timer = setTimeout(()=>{
                    this.showAd()
                    clearTimeout(this.timer)
                },1000)
            })
        }
    }
}